package com.zx.designpattern.presenter;

import com.zx.designpattern.model.impl.GirlModelImpl;
import com.zx.designpattern.model.IBaseModel;
import com.zx.designpattern.view.IBaseView;

/**
 * @作者 Administrator
 * @创建时间 2018-02-03 22:06
 * @描述 GirlsPresenter
 * @修改时间 2018-02-03 22:06
 * @修改描述
 * @修改者 Administrator
 **/
public class GirlsPresenter<T extends IBaseView> extends BasePresenter<T> {

    //model层引用
    IBaseModel baseModel = new GirlModelImpl();


    public GirlsPresenter() {
    }


    //UI逻辑1
    public void fetch() {
        if (baseView != null) {
            baseView.get().showLoading();
            if (baseModel != null) {
                baseModel.loadData(new IBaseModel.CallBack() {
                    @Override
                    public void success(Object data) {
                        baseView.get().showView(1, data);
                        baseView.get().hideLoading();
                    }

                    @Override
                    public void fail(Object data) {
                        baseView.get().hideLoading();

                    }
                });
            }
        }
    }

    //UI逻辑3
    public void addData() {
        if (baseView != null) {
            baseView.get().showLoading();
            if (baseModel != null) {
                baseModel.loadData(new IBaseModel.CallBack() {
                    @Override
                    public void success(Object data) {
                        baseView.get().showView(3, data);
                        baseView.get().hideLoading();
                    }

                    @Override
                    public void fail(Object data) {
                        baseView.get().hideLoading();

                    }
                });
            }
        }
    }

    //UI逻辑2
    public void clearData() {
        if (baseView != null) {
            baseView.get().showLoading();
            baseView.get().showView(2, null);
            baseView.get().hideLoading();
        }
    }

}
